﻿@model NC.Cather.UrlList
@{
    ViewBag.Title = "Edit";
}
<script src="~/Content/IsLoading/jquery.isloading.min.js"></script>
<link href="~/Content/IsLoading/isloading.css" rel="stylesheet" />
<section class="content-header">
    <h1>
        网站分类列表信息
        <small>13 new messages</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="@Url.Action("Index",new {targetId=Request.QueryString["targetId"]})"><i class="fa fa-dashboard"></i>首页</a></li>
        <li class="active">编辑</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-6">
            <div class="box box-solid">
                <div class="box-body">
                    @using (Html.BeginForm())
                    {
                        @Html.AntiForgeryToken()
                        <div class="form-horizontal">
                            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                            @Html.Partial("Form")
                            <div class="form-group">
                                <div class="col-md-offset-2 col-md-10">
                                    <input type="submit" value="创建" class="btn btn-primary" />
                                </div>
                            </div>
                        </div>
                    }
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="box box-solid">
                <div class="box-body">
                    <div class="nav-tabs-custom">
                        <ul class="nav nav-tabs">
                            <li class="active" data-id="ContainerContent"><a href="#ContainerContentTab" data-toggle="tab" aria-expanded="false">容器内容</a></li>
                            <li class="" data-id="AselectorContent"><a href="#AselectorContentTab" data-toggle="tab" aria-expanded="true">a标签</a></li>
                            <li class="" data-id="PagerContent"><a href="#PagerContentTab" data-toggle="tab" aria-expanded="false">分页内容</a></li>
                        </ul>
                        <div class="tab-content">
                            <div class="tab-pane active" id="ContainerContentTab">
                                <div class="clearfix">
                                    <div class="row">
                                        <div class="control-label col-md-2">容器内容</div>
                                        <div class="col-md-10">
                                            <textarea rows="16" class="form-control" id="ContainerContent"></textarea>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12" id="ContainerContentHtml">

                                        </div>
                                    </div>
                                </div>
                            </div><!-- /.tab-pane -->
                            <div class="tab-pane" id="AselectorContentTab">
                                <div class="clearfix">
                                    <div class="control-label col-md-2">a标签内容</div>
                                    <div class="col-md-10">
                                        <textarea rows="16" class="form-control" id="AselectorContent"></textarea>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-12" id="AselectorContentHtml">

                                    </div>
                                </div>
                            </div>
                            <div class="tab-pane" id="PagerContentTab">
                                <div class="clearfix">
                                    <div class="control-label col-md-2">分页内容</div>
                                    <div class="col-md-10">
                                        <textarea rows="16" class="form-control" id="PagerContent"></textarea>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-12" id="PagerContentHtml">
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-3">当前导航模板：</div>
                                    <span class="col-md-9" id="pagerNow"></span>
                                </div>
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="btn btn-success btn-block" onclick="PageTest(-1)">上一页</div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="btn btn-success btn-block" onclick="PageTest(1)">下一页</div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</section>
<script type="text/javascript">

    //全局变量设置
    var pagerIsValid = false,
        pagerIndex = 0,
        queryStringIsValid = false,
        postBodyIsValid = false;


    function checkUrlIsValide() {
        var url = $("#Url").val();
        $.ajax({
            url: "@Url.Action("CheckUrl","Target")",
            data: { url: url },
            type: "post",
            success: function (data) {
                if (data.status == 0) {
                    showError(data.msg);
                }
            },
            error: function (error) {
                showError("服务器出错");
            }
        });
    }

    //内容选择器
    function ContentSelectorTest() {
        var contentSelector = $("#ContentSelector").val();
        var url = $("#Url").val();
        //        var method = getRadioCheckValue();
        if (contentSelector == "" || url == "") {
            showError("列表地址和容器选择器不允许为空");
            return;
        }
        $.isLoading({ text: "Loading" });
        $.ajax({
            url: "@Url.Action("GetContentSelector")",
            type: "post",
            //            data: { contentSelector: contentSelector, url: url ,method:method},
            data: { contentSelector: contentSelector, url: url },
            success: function (data) {
                $.isLoading("hide");
                if (data.status == 1) {
                    $("#ContainerContent").val(data.msg);
                    $("#ContainerContentHtml").html(data.msg);
                    $.isLoading("hide");
                } else {
                    showError(data.msg);
                    ClearAndSetTab("ContainerContent");
                }
            },
            error: function (error) {
                $.isLoading("hide");
                showError("服务器出错");
            }
        });
    }
    //a标签选择器
    function ASelectorTest() {
        var contentSelector = $("#ContentSelector").val();
        var aSelector = $("#ASelector").val();
        var url = $("#Url").val();
        if (contentSelector == "" || url == "") {
            showError("列表地址和容器选择器不允许为空");
            return;
        }
        $.isLoading({ text: "Loading" });
        $.ajax({
            url: "@Url.Action("GetASelector")",
            type: "post",
            data: { contentSelector: contentSelector, url: url, aSelector: aSelector },
            success: function (data) {
                $.isLoading("hide");
                ClearAndSetTab("AselectorContent");
                if (data.status == 1) {
                    $("#AselectorContent").val(data.msg);
                    $("#AselectorContentHtml").html(data.msg);
                } else {
                    showError(data.msg);
                }
            },
            error: function (error) {
                $.isLoading("hide");
                showError("服务器出错");
            }
        });
    }

    function ClearAndSetTab(id) {
        $(".nav-tabs li").removeClass("active");
        $(".nav-tabs li[data-id=" + id + "]").addClass("active");
        $(".tab-content .tab-pane").removeClass("active");
        $("#" + id + "Tab").addClass("active");
    }

    function getRadioCheckValue() {
        var radios = $("input[type=radio]");
        if (radios.eq(0).prop("checked"))
            return "get";
        return "post";
    }


    //分页数据测试
    function PagerSelectorTest(pagerSelectorParams) {
        var pagerSelector = $("#PagerSelector").val();
        //没有开启pager分页
        if (!$("#EnablePager").prop("checked"))
            return;
        if (!window.pagerIsValid) {
            showError("分页模板格式错误");
            return;
        }
        var contentSelector = $("#ContentSelector").val();
        var aSelector = $("#ASelector").val();
        var url = $("#Url").val();
        if (contentSelector == "" || url == "") {
            showError("列表地址和容器选择器不允许为空");
            return;
        }
        if (!window.queryStringIsValid) {
            showError("queryString参数格式错误");
            return;
        }
        url += $("#QueryStringParams").val();
        $.isLoading({ text: "Loading" });
        //开始设置全局分页数据
        if (arguments.length == 0) {
            $("#pagerNow").html(setPagerIndex(pagerSelector));
            url += "&" + setPagerIndex(pagerSelector);
        } else {
            $("#pagerNow").html(pagerSelectorParams);
            url += "&" + pagerSelectorParams;
        }
        $.ajax({
            url: "@Url.Action("GetPagerSelector")",
            type: "post",
            data: { contentSelector: contentSelector, url: url, aSelector: aSelector, pagerSelector: pagerSelector },
            success: function(data) {
                $.isLoading("hide");
                ClearAndSetTab("PagerContent");
                if (data.status == 1) {
                    $("#PagerContent").val(data.msg);
                    $("#PagerContentHtml").html(data.msg);
                } else {
                    showError(data.msg);
                }
            },
            error: function(error) {
                $.isLoading("hide");
                showError("服务器出错");
            }
        });
    }

    //分页设置
    function PageTest(select) {
        var pagerSelector = $("#PagerSelector").val();
        window.pagerIndex += select;
        var param = setPagerNum(pagerSelector, window.pagerIndex);
        PagerSelectorTest(param);
    }



    function checkPagerIsValid() {
        if (!$("#EnablePager").prop("checked")) {
            window.pagerIsValid = false;
            return;
        }
        var pager = $("#PagerSelector").val();
        $.ajax({
            url: "@Url.Action("CheckPagerIsValid")",
            type: "post",
            data: { pagerSelector: pager },
            success: function (data) {
                if (data.status == 0) {
                    showError(data.msg);
                    window.pagerIsValied = false;
                } else {
                    window.pagerIsValid = true;
                }
            },
            error: function (error) {
                showError("服务器出错");
            }
        });
    }

    function checkQueryIsValid() {
        var queryString = $("#QueryStringParams").val();
        if (!$("#EnablePager").prop("checked")) {
            window.queryStringIsValid = false;
            return;
        }
        if (queryString == "") {
            showError("请输入queryString参数");
            return;
        }
        queryString += "&";
        $.ajax({
            url: "@Url.Action("CheckQueryStringIsValid")",
            type: "post",
            data: { queryString: queryString },
            success: function (data) {
                if (data.status == 0) {
                    showError(data.msg);
                    window.queryStringIsValid = false;
                } else {
                    window.queryStringIsValid = true;
                }
            },
            error: function (error) {
                showError("服务器出错");
            }
        });

    }


    //设置分页模板当前页面数据
    function setPagerIndex(pagerSelector) {
        var pageIndex = getPagerNum(pagerSelector);
        if (isNaN(pageIndex)) {
            showError("分页模板{}内部参数格式错误");
            return;
        }
        window.pagerIndex = parseInt(pageIndex);
        return setPagerNum(pagerSelector, window.pagerIndex);
    }
    function getPagerNum(pagerSelector) {
        var firstIndex = pagerSelector.indexOf('{');
        var lastIndex = pagerSelector.indexOf('}');
        var num = pagerSelector.substring(firstIndex + 1, lastIndex);
        return num;
    }
    function setPagerNum(pagerSelector,pageIndex) {
        var firstIndex = pagerSelector.indexOf('{');
        var lastIndex = pagerSelector.indexOf('}');
        var num = pagerSelector.substring(firstIndex, lastIndex + 1);
        return pagerSelector.replace(num, pageIndex);
    }
    function pagerChange() {
        console.log("sffsdf");
        if ($("#EnablePager").prop("checked")) {
            $(".pager-show").css("display", "block");
        } else {
            $(".pager-show").css("display", "none");
        }
    }
    pagerChange();
</script>  